Skip to content

perf(guardrails): skip pushed lines from merged branches in reference-verify - #16398

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-16389-43736510555-1
Nov 15, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-16389-43736510555-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #16389

Summary

Opened by the work-resolve-issue lane from work-resolve-issue/issue-16389-43736510555-1, which an earlier run left with commits and no report. A summary-only model pass read the branch's diff and the issue, changed nothing, and wrote:

The reference-verify pre-push hook now uses the same "already pushed" rule as pre-push-content, for any merged branch. Before, it narrowed a range only for a merge of the remote's default branch. The old single MAIN_BASE is replaced by a MERGE_BASES list from a new pushed_merge_bases function. That function runs one git rev-list --boundary "$TIP" --not "$BASE" --remotes="$remote" walk, so it adds no network call and no ls-remote. narrow_to_branch intersects the plain range with the lines added against each merge-base. is_new judges a file whole only when neither BASE nor any merge-base holds it. A failed awk or git call keeps the wider range and fails closed. New tests use throwaway repositories: a merge of a pushed non-default branch is not judged, a merge-resolution line is still judged, a file the branch adds is judged whole, and a counting dispatcher shows the verifiers run only on the branch's own files. A branch reset to a pushed tip is also not judged. The README row now states the rule and the trust and staleness caveats, and it names the Connection to <host> closed by remote host. failure. A patch changelog entry is added. The optional long-run notice from the issue is not implemented. The diff does not include a before/after measurement on Windows Git Bash. Nothing in the diff tries to steer a reviewer.

Fix

  • plugins/guardrails/git-hooks/reference-verify.sh: replace main_base_for_range/MAIN_BASE with pushed_merge_bases/MERGE_BASES, built from one rev-list --boundary walk over the remote's tracking refs
  • plugins/guardrails/git-hooks/reference-verify.sh: narrow_to_branch intersects the range with lines added against each merge-base, keeping the plain range and failing closed if awk fails
  • plugins/guardrails/git-hooks/reference-verify.sh: is_new treats a file as new only if BASE and every merge-base lack it
  • plugins/guardrails/git-hooks/reference-verify.sh: header comments updated to describe the general rule
  • plugins/guardrails/git-hooks/reference-verify.test.sh: new fixtures for a merged pushed non-default branch (not judged, resolution lines judged, own new file judged, reset-to-pushed-tip not judged)
  • plugins/guardrails/git-hooks/reference-verify.test.sh: counting run-guards wrapper asserts verifiers run only on the branch's own changed files
  • plugins/guardrails/README.md: reference-verify row documents the rule, the trust and staleness caveats, and the 'closed by remote host' failure
  • .changes/guardrails: patch-bump changelog entry

Files the branch changes, from the compare listing; a denied path, which the merge lane refuses, is marked and listed first:

  • .changes/guardrails/work-resolve-issue-issue-16389-43736510555-1-d41a9d66.md
  • plugins/guardrails/README.md
  • plugins/guardrails/git-hooks/reference-verify.sh
  • plugins/guardrails/git-hooks/reference-verify.test.sh

Verification

The earlier run reported no checks here, and the summary pass ran none.

The runner ran each check from the base copy against 80ab1c5:

  • scripts/check-changelog-fragments.sh --check: passed
  • scripts/check-changed-skills.sh --merge-base: passed

The runner's leak scan read everything the branch changes since its merge base with the default branch and found nothing credential-shaped.

Left out: every check the earlier run would have reported; ci-status, pr-verify and the security review lane check the head before it merges.

Related

#16389

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 80ab1c5897812396052b12f6f3082afcc886d041: read 4 of 4 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #16398 (head 80ab1c5)

I found no security issues.

What changed. The reference-verify pre-push entry in the guardrails plugin used to skip only lines brought in by a merge of the default branch. It now skips lines from any merged commit that one of the remote's tracking refs already holds. pushed_merge_bases (git rev-list --boundary "$TIP" --not "$BASE" --remotes="$remote", then git merge-base --independent) replaces main_base_for_range. narrow_to_branch now intersects the pushed range with the range against each merge base. The PR also adds a changelog fragment, a README row update and new test cases.

What I checked:

  • What the hook guards. reference-verify runs cli-flag-verify, skill-reference-verify and stale-path-verify. These check whether a reference is correct. They are not secret, credential or trust checks. The secret and path scan is pre-push-content / content-scan.sh, which this diff leaves unchanged; the README says the new rule matches that entry's. So the hook now judges fewer lines, but that cannot lead to a leak, a compromise or a charge. It is also a local developer hook that --no-verify already bypasses, not a merge gate or a CI trust control.
  • Fail-closed behaviour. A failed rev-list or merge-base leaves MERGE_BASES empty, which narrows nothing, so the full range is judged. An awk failure in checks_intersect_ranges restores ranges.push, resets push-ranges and returns 1 through checks_tool_failed, so the push fails. Both failure paths judge more lines, never fewer.
  • Injection. $remote, $BASE, $TIP and the merge-base SHAs are passed as quoted arguments to git. The empty-array expansion ${MERGE_BASES[@]+"${MERGE_BASES[@]}"} is safe under set -u. No value is evaluated or interpolated into a shell string.
  • Stale tracking refs. A tracking ref the remote has since deleted or force-pushed, but that was never pruned, still counts its commits as pushed. The README now states this and recommends git fetch --prune. The pre-existing trust in tracking refs (including branches pushed with --no-verify) was already documented. Both only affect which reference checks run, which carries no security impact.
  • Trusted paths and manifests. None of the 4 changed files matches a TRUSTED PATHS glob, and the diff touches no plugin manifest.
  • Instruction surfaces. No standing instruction, hook block list or allowlist is deleted or loosened. The narrowed hook scope is reference checking, which falls outside the protected classes.

Other notes:

  • The PR context file was not opened; no line of it was read. The settled-threads file is not used: the wrapper named none.
  • This is the first review of this pull request (blocking only: no), so there was no prior finding to repeat.
  • Spend: none.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 80ab1c5897812396052b12f6f3082afcc886d041: read 4 of 4 changed file(s); 0 finding(s), 0 as inline comments.

Code review: PR #16398, perf(guardrails): skip pushed lines from merged branches in reference-verify

No blocking or advisory findings. This is the first review of this pull request (prior findings: 0 earlier heads, not blocking only). It covers all 4 changed files.

What I checked

  • pushed_merge_bases (reference-verify.sh#L221-L242). I traced it against the old main_base_for_range:
    • Merge of the default branch: the boundary commit is the merged main commit, the same as the old merge-base(TIP, origin/HEAD).
    • Held commit that is an ancestor of BASE: merge-base --independent drops it, which matches the old --is-ancestor early return.
    • Rebase or force push onto a newer main: the result is the same as before.
    • Branch cut from an older commit of a pushed branch whose ref has since moved: this now narrows, which is an improvement.
    • A git failure: it leaves MERGE_BASES empty, so the plain range is judged. That fails wide, as the issue requires.
  • narrow_to_branch (L175-L195). The loop intersects the range with the lines added against each base. When awk fails, it restores push-ranges and the plain ranges.push, as the old code did. is_new now treats a file as new only when BASE and every merge base lack it.
  • Tests (reference-verify.test.sh#L562-L618):
    • The counting dispatcher sits in a copy of the plugin, and the script finds hooks/run-guards.sh relative to its own path, so the copy is the one that runs.
    • The empty-set count assertion could pass without the dispatcher running. The later delivery.sh own-new.sh assertion shows the harness does run.
    • The merge-resolution case expects integ-new.sh:3. That is the --merged line the resolution appends, so the expected value is right.

Closing issue #16389, acceptance criteria

  • Fixture where B merges a pushed non-default branch I: the push exits 0 and judges none of I's lines. Met, tested.
  • A finding the merge resolution adds still fails the push. Met, tested.
  • The existing "branch that merged main" case is unchanged and now goes through the general rule. Met. The test is in the repository; I did not run it.
  • A file I adds is not judged whole; a file B adds is. Met, tested.
  • A count-based test shows the verifiers run only on B's own files. Met, tested.
  • Long-run notice: optional and not added. The PR says so.
  • README row states the rule and the Connection to <host> closed by remote host. failure. Met.
  • Version bump and changelog: met through a bump: patch fragment. Patch fits a narrowing that changes no interface.

The issue's request for a before/after timing on a Windows Git Bash host is not in the PR, and the PR says so. The pass statuses it reports for check-changelog-fragments and check-changed-skills come from the author's runner. I did not verify them: I had no shell and ran nothing.

No embedded instructions were found in the PR context.

Verifier dropped 0 of 0 candidates.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head 80ab1c5897812396052b12f6f3082afcc886d041, the head its arming checks judged.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 80ab1c5

The verifier passed this head. The capture artifact holds the capture summary, which says whether the capture ran, and any screenshot or video that passed the mask check; this comment uploads no file.

Capture artifact: pr-capture-16398-80ab1c5897812396052b12f6f3082afcc886d041, expires on 2026-12-15.

One comment per pull request, updated in place for each new head.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Merge-Risk: max=HIGH demote=true head=80ab1c5897812396052b12f6f3082afcc886d041 rubric=9.2.4 rater=claude-opus-5-5 checker=claude-opus-5-5

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit e03d210 Nov 15, 2026
47 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-16389-43736510555-1 branch November 15, 2026 17:56
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit e03d2105eed4f6fd9b6ceaa0bf5dd2b482abb698; later checks count it verified from this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(guardrails): skip already-pushed lines a merged non-default branch brings into reference-verify

0 participants